home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGNG_C
/
CSTUFF.LZH
/
FWRITE.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-09-14
|
5KB
|
107 lines
;fwrite.asm - a modification of FastWrite.PAS
; to run under Microsoft C using the MASM Assembler
; Writes directly to the screen buffer
;
; This routine is based on the FastWrite routine submitted
; to the Borland SIG on CompuServe. It has been tested for
; use with programs written under the Microsoft C Compiler,
; version 3.0, under the small memory model only. Its use
; with the medium and large memory models is not guaranteed,
; due to the fact that these models sometimes change the
; value of DS, which this routine uses to locate the string.
; In calling the routine from a C program, the value for
; the string 'st' can be supplied by passing a pointer to
; a string or, as is convenient with C, a string literal
; itself (the program will take the address of the 0th element
; of the string).
;
; Acknowledgements:
; Brian Foley submitted the Turbo Pascal inline code version
; of this routine to the Borland SIG on CompuServe. David B.
; Rein helped to convert the code, and some final modifications
; were done by Michael D. Most.
;
; Questions may be answered by contacting Brian Foley on
; CompuServe [76317,3247], or Mike Most [70446,1244].
;
;
;**********************************************************
;* *
;* usage: fwrite(st,row,col,attr) *
;* char *st; *
;* int row, col, attr; *
;* *
;**********************************************************
;
IGROUP group _TEXT
assume CS:IGROUP
;
_TEXT segment byte public 'CODE'
public _fwrite
_fwrite proc near
push bp ;MSC entry
mov bp,sp
push di
mov bx,si ;save SI in BX
mov ax,40h ;get video mode
mov es,ax
mov dl,es:[49h] ;DL=Video mode, stored by BIOS
mov di,[bp+6] ;DI=Row
dec di ;make row 0-24 instead of 1-25
mov cl,4 ;CL=4, CH=0
shl di,cl ;DI=Row*32
mov ax,di ;store in AX
shl di,1 ;DI=Row*32
shl di,1 ;DI=Row*64
add di,ax ;di=row*80
add di,[bp+8] ;Add (Col +1) to di
dec di ;DI=(Row*80) + Column
shl di,1 ;account for attribute byte
mov si,Word Ptr[bp+4] ;DS:SI points to String
mov ah,[bp+10] ;AH = attribute
cmp dl,7 ;Mono??
je _mono
mov dx,0b800h ;base of video buffer
mov es,dx ;ES = segment for color memory
mov dx,03dah ;6845 port address
_getnext: lodsb ;load next char into al
or al,al ;test for null character
jz _exit ;exit if it's a null
mov cx,ax ;store video word in CX
cli ;no interrupts
_waitnoh: in al,dx ;get 6845 status
test al,8 ;Vertical retrace?
jnz _store ;if so, go
rcr al,1 ;else, wait for end of
jc _waitnoh ;horizontal retrace
_waith: in al,dx ;get 6845 status again
rcr al,1 ;wait for horizontal
jnc _waith ;retrace
_store: mov ax,cx ;move word back to AX..
stosw ;and then to screen
sti ;allow interrupts
jmp short _getnext ;get next character
_mono: mov dx,0b000h
mov es,dx ;ES = segment for mono memory
_next: lodsb ;Load next char into AL
or al,al ;Test for null char
jz _exit ;Exit if it's a null
stosw ;Move video word into place
jmp short _next ;get next character
_exit: mov si,bx ;restore SI from BX
pop di ;MSC cleanup_ TEXT
mov sp,bp
pop bp
ret
_fwrite endp
_TEXT ends
end